<div class="page-inner">
	<div class="row">

		<div class="col-md-12">
			<div class="card">
				<div class="card-header">
					<div class="d-flex align-items-center">
						<button class="btn btn-primary btn-round ml-auto" data-toggle="modal" data-target="#myModal" onclick="openModal('/product/add')">
							<i class="fa fa-plus"></i>
							我要添加
						</button>
					</div>
				</div>
				
				<div class="card-body">
					<div class="table-responsive">
						<table id="add-row" class="display table table-striped table-hover" >
							<thead>
								<tr>
									<th>名称</th>
									<th>CPU</th>
									<th>内存</th>
									<th>并发</th>
									<th>操作系统</th>
									<th>网络类型</th>
									<th>带宽大小M</th>
									<th>类别</th>
									<th style="width: 5%">操作</th>
								</tr>
							</thead>
							<tbody>
								{%for i, v in ipairs(result) do%}
									<tr>
										<td>{*v.name*}</td>
										<td>{*v.cpu*}</td>
										<td>{*v.memory*}</td>
										<td>{*v.concurrent*}</td>
										<td>{%if v.system == 1 then%}windows{%else%}Linux{%end%}</td>
										<td>{%if v.network_type == 1 then%}固定带宽{%elseif v.network_type == 2 then%}按需{%else%}无需外网{%end%}</td>
										<td>{*v.network_size*}</td>
										<td>{*v.dict_name*}</td>
										<td>
											<div class="form-button-action">
												<button type="button" class="btn btn-link btn-primary" data-toggle="modal" data-target="#myModal" onclick="openModal('/product/edit/{*v.id*}')">
													<i class="far fa-edit"></i> 编辑
												</button>
												<button type="button" data-toggle="tooltip" title="" class="btn btn-link btn-danger" data-original-title="Remove" onclick="del({*v.id*},'{*v.name*}')">
													<i class="fas fa-trash-alt"></i> 删除
												</button>
											</div>
										</td>
									</tr>
								{%end%}
							</tbody>
						</table>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>
<script>
// Add Row
$('#add-row').DataTable({
	"pageLength": 10,
});

var action = '<td> <div class="form-button-action"> <button type="button" data-toggle="tooltip" title="" class="btn btn-link btn-simple-primary btn-lg" data-original-title="Edit Task"> <i class="fa fa-edit"></i> </button> <button type="button" data-toggle="tooltip" title="" class="btn btn-link btn-simple-danger" data-original-title="Remove"> <i class="fa fa-times"></i> </button> </div> </td>';

function del(id,name){
	swal({
	title: '危险操作！',
	text: '确定要删除【'+name+'】吗？',
	type: 'warning',
	buttons:{
		confirm: {
			text : 'Yes!',
			className : 'btn btn-success'
		},
		cancel: {
			visible: true,
			className: 'btn btn-danger'
		}
	}
	}).then((Delete) => {
		if (Delete) {
			$.ajax({
				type: "GET",
				url: "/product/del/"+id,
				success:function(data){
					swal("删除完成!", {
						buttons: false,
						timer: 1000,
					});
					toMune('/product/query');
				},
				error:function(){
					alert('error');
				}
			});	
		} else {
			swal.close();
		}
	});
}
</script>